package com.tianyang.yukuaifuzs.module.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.tianyang.yukuaifuzs.R;
import com.tianyang.yukuaifuzs.business.main.adapter.PosChannelAdapter;
import com.tianyang.yukuaifuzs.business.main.bean.ChannelOutput;
import com.tianyang.yukuaifuzs.module.dialog.interfaces.ICallbackListener;
import com.tianyang.yukuaifuzs.module.roundview.RoundTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Description：新增店铺
 * Created by xyj on 2024/6/16
 */
public class PosChannelDialog extends Dialog {

    @BindView(R.id.channelRv)
    RecyclerView channelRv;
    @BindView(R.id.confirmRtv)
    RoundTextView confirmRtv;

    private PosChannelAdapter vPosChannelAdapter;

    private ChannelOutput mOutput;

    private ICallbackListener<ChannelOutput> listener;

    public void setListener(ICallbackListener<ChannelOutput> listener) {
        this.listener = listener;
    }

    public PosChannelDialog(Context context, List<ChannelOutput> channelOutputs, boolean isAddStore) {
        super(context, R.style.dialog_normal);
        setContentView(R.layout.dialog_pos_channel);
        ButterKnife.bind(this);

        if (isAddStore) {
            confirmRtv.setText("确认新增");
        } else {
            confirmRtv.setText("确认");
        }
        channelRv.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
        vPosChannelAdapter = new PosChannelAdapter();
        channelRv.setAdapter(vPosChannelAdapter);
        if (channelOutputs != null && !channelOutputs.isEmpty()) {
            mOutput = channelOutputs.get(0);
            vPosChannelAdapter.setNewData(channelOutputs);
        }
        vPosChannelAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                mOutput = ((PosChannelAdapter)adapter).getItem(position);
                vPosChannelAdapter.setChooseIndex(position);
            }
        });
    }

    @OnClick({R.id.confirmRtv})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.confirmRtv:
                if(listener != null) {
                    listener.callback(mOutput);
                }
                dismiss();
                break;
        }
    }
}
